<template>
	<div class="loginbody">
		<div class="logindata">
			<div class="logintext">
				<h2>银行管理系统</h2>
			</div>
			<div class="formdata">
				<el-form ref="form" :model="form" :rules="rules">
					<el-form-item prop="username">
						<el-input v-model="form.username" clearable placeholder="请输入账号"></el-input>
					</el-form-item>
					<el-form-item prop="password">
						<el-input
							v-model="form.password"
							clearable
							placeholder="请输入密码"
							show-password
							@keyup.enter.native="login"
						></el-input>
					</el-form-item>
				</el-form>
			</div>
			<div class="tool">
				<span class="shou" @click="forgetPassword">忘记密码？</span>
			</div>
			<div style="display: flex; justify-content: center">
				<el-button type="primary" @click="login" style="width: 100px">登录</el-button>
			</div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			form: {
				password: "",
				username: ""
			},
			checked: false,
			rules: {
				username: [
					{
						required: true,
						message: "请输入用户名",
						trigger: "blur"
					}
				],
				password: [
					{
						required: true,
						message: "请输入密码",
						trigger: "blur"
					}
				]
			}
		};
	},

	methods: {
		login() {
			let params = new URLSearchParams();
			params.append("username", this.form.username);
			params.append("password", this.form.password);

			this.axios.post("api/login", params).then(res => {
				if (res.data.code == 200) {
					this.$message.success(res.data.data);
					this.$router.push("/");
					localStorage.setItem("JWToken", res.data.msg);
				} else {
					this.$message.error(res.data.data);
				}
			});
		},

		forgetPassword() {
			//我是谁
		}
	}
};
</script>

<style scoped>
.loginbody {
	width: 100%;
	height: 100%;
	min-width: 1000px;
	background-image: url("@/assets/login.png");
	background-size: 100% 100%;
	background-position: center center;
	overflow: auto;
	background-repeat: no-repeat;
	position: fixed;
	line-height: 100%;
	padding-top: 150px;
}

.logintext {
	margin-bottom: 20px;
	line-height: 50px;
	text-align: center;
	font-size: 30px;
	font-weight: bolder;
	color: white;
	text-shadow: 2px 2px 4px #000000;
}

.logindata {
	width: 400px;
	height: 300px;
	transform: translate(-50%);
	margin-left: 50%;
}

.tool {
	display: flex;
	justify-content: flex-end;
	color: #101010;
}

.butt {
	margin-top: 10px;
	text-align: center;
}

.shou {
	cursor: pointer;
}
</style>
